import { loginApi } from '@/api/user.js'
import { getToken, setToken, delToken } from '@/utils/storage.js'
export default {
  state () {
    return {
      token: getToken(),
      userInfo: {}
    }
  },
  mutations: {
    //修改token值为获取到的token
    changeToken (state, token) {
      state.token = token
      setToken(token)
    },
    removeToken (state) {
      state.token = null
      delToken()
    },
    setUser (state, user) {
      state.userInfo = user
    }
  },
  actions: {
    async asyncLogin ({ commit }, ruleForm) {
      /* token==>vuex+本地存储 */
      const res = await loginApi(ruleForm)//用户登陆
      console.log(res, 99887)
      commit('changeToken', res.data.token)
    }
  },
  getters: {},
  namespaced: true
}